/**
 * @param {string} s
 * @return {number}
 */
 var romanToInt = function(s) {
    const map=new Map([['I',1],['V',5],['X',10],['L',50],['C',100],['D',500],['M',1000]]);
    const length=s.length;
    let sum=0;
    for(let i=0;i<length;i++){
        let char=s[i];
        let charlast=s[i+1];
        if(charlast && map.get(char)<map.get(charlast)){
            sum -=map.get(char);
        }
        else{
            sum +=map.get(char);
        }
    }
    return sum;
};
console.log(romanToInt("LVIII"))